<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form :inline="true" :model="listPram" ref="dataForm" @keyup.enter.native="getDataList()">
            <el-form-item prop="key">
              <el-input v-model="listPram.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-button @click="getDataList()">查询</el-button>
              <el-button type="primary" @click="resetFields()">重置</el-button>
              <el-button v-hasPermi="['admin:weekscore:save']" type="primary" @click="addOrUpdateHandle()">新增</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    <el-table
      :data="listData.list"
      v-loading="dataListLoading"
      size="mini"
      highlight-current-row
      class="table"
      :header-cell-style=" {fontWeight:'bold'}">
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="主键ID">
      </el-table-column>
      <el-table-column
        prop="score"
        header-align="center"
        align="center"
        label="分数">
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="打分时间">
      </el-table-column>
      <el-table-column
        prop="updateTime"
        header-align="center"
        align="center"
        label="更新时间">
      </el-table-column>
      <el-table-column
        prop="leaveTime"
        header-align="center"
        align="center"
        label="离开房间时间">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" v-hasPermi="['admin:weekscore:update']" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" v-hasPermi="['admin:weekscore:delete']" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
      <div class="block-pagination">
          <el-pagination
            :current-page="listPram.page"
            :page-sizes="constants.page.limit"
            :layout="constants.page.layout"
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :total="listData.total"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
    </el-card>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import * as weekscore from "@/api/weekscore";
  import AddOrUpdate from './modules/weekscoreEdit'
  export default {
    data () {
      return {
        listPram: {
          key: null,
          cid: null,
          page: 1,
          limit: this.$constants.page.limit[0],
        },
        constants: this.$constants,
        listData: { list: [], total: 0 },
        dataListLoading: false,
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    created () {
      this.getDataList()
    },
    methods: {
      resetFields() {
        this.$refs["dataForm"].resetFields();
      },

      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        weekscore.list(this.listPram).then((data) => {
          this.listData = data;
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.listPram.limit = val;
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.listPram.page = val;
        this.getDataList()
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (rowData) {
        this.$confirm("确定删除当前数据", "提示").then((result) => {
          weekscore.deleteAc(rowData).then((data) => {
            this.$message.success("删除数据成功");
            this.getDataList();
          });
        });
      }

    }
  }
</script>
